package com.advantage.accounts;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.advantage.R;
import com.advantage.accounts.transactions.TransactionActivity;

/**
 * Created with IntelliJ IDEA.
 * User: hirsche
 * Date: 13/04/14
 * Time: 14:42
 * To change this template use File | Settings | File Templates.
 */
public class AccountsFragment extends Fragment {

    public static final String ACCOUNT_NUMBER = "account_number";

    ListView accountsListView;
    private String[] accounts;

    public AccountsFragment() {
        // Empty constructor required for fragment subclasses
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_accounts, container, false);
        accountsListView = (ListView)rootView.findViewById(R.id.accounts_list_view);

        accountsListView.setOnItemClickListener(new AccountsItemClickListener());
        accounts = getResources().getStringArray(R.array.accounts_array);
        accountsListView.setAdapter(new ArrayAdapter<String>(this.getActivity(),
                R.layout.accounts_list_item, R.id.account_item, accounts));
        return rootView;
    }

    private class AccountsItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent intent = new Intent(view.getContext(),TransactionActivity.class);
            getActivity().startActivity(intent);
        }
    }
}
